package com.uchiyou.walletwrapper.util;

import com.fasterxml.jackson.databind.JsonNode;
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;


public class AddressUtil {
    private static JsonRpcHttpClient client = ClientUtil.getClient();

    /**
     * 1. 获取当前钱包中所有的 label
     * @return
     */
    public static String listlabels() {
        String result = null;
        try {
            result = client.invoke("listlabels", new Object[] {}, JsonNode.class).toString();
        }catch (Throwable e){
            e.printStackTrace();
        }
        return  result;
    }

    /**
     * 2 获取指定 label 下所有的地址
     * @return
     */
    public static String getaddressesbylabel(String label) {
        String result = null;
        try {
            result = client.invoke("getaddressesbylabel", new Object[] {label}, JsonNode.class).toString();
        }catch (Throwable e){
            e.printStackTrace();
        }
        return  result;
    }

    /**
     * 3. 生成和 label 关联的地址
     * @param label
     * @return
     */
    public static String getNewaddress(String label) {
        String result = null;
        try {
            result = client.invoke("getnewaddress", new Object[] {label}, JsonNode.class).toString();
        }catch (Throwable e){
            e.printStackTrace();
        }
        return  result;
    }
    public static String getNewaddress() {
        String result = null;
        try {
            result = client.invoke("getnewaddress", new Object[] {}, JsonNode.class).toString();
        }catch (Throwable e){
            e.printStackTrace();
        }
        return  result;
    }

    /**
     * 4. 获取当前钱包总余额
     * @return
     */
    public static String getbalance() {
        String result = null;
        try {
            result = client.invoke("getbalance", new Object[] {}, JsonNode.class).toString();
        }catch (Throwable e){
            e.printStackTrace();
        }
        return  result;
    }


}
